<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-promotion"></i>库存管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-promotion"></i>入库管理</el-breadcrumb-item>
      <el-breadcrumb-item>新增商品</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider content-position="left"></el-divider>
    <div class="rule-form">
      <el-form :model="ruleForm" ref="ruleForm" label-width="130px" class="demo-ruleForm" @submit.native="submit()">
        <el-form-item label="商品名称" prop="productName">
          <el-select v-model="ruleForm.productName" placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.productName"
                :label="item.label"
                :value="item.productName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="进货量" prop="orderAmount">
          <el-input v-model="ruleForm.orderAmount"></el-input>
        </el-form-item>
        <el-form-item label="供货商名字" prop="userName">
          <el-input v-model="ruleForm.userName"></el-input>
        </el-form-item>
        <el-form-item label="供货商电话" prop="userPhone">
          <el-input v-model="ruleForm.userPhone"></el-input>
        </el-form-item>
        <el-form-item label="单价" prop="goodsPrice">
          <el-input v-model="ruleForm.goodsPrice"></el-input>
        </el-form-item>


        <el-form-item>
          <el-button type="primary" @click="save">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>




</template>

<script>
import axios from "axios";

export default {
    data(){
      return{
        options:[],
        ruleForm: {
          productName: "",
          orderAmount: "",
          userName:"",
          userPhone:"",
          goodsPrice:""
        }

      }
    },
    methods:{
      gotoWare(){
        this.$router.push('/view/inventory/ware');
      },
      fetchData() {
        axios.get('http://localhost:9902/category/selectCategoryName') //
            .then(response => {
              this.options = response.data.data;
            })
            .catch(error => {
              console.error(error);
            });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      save(){
        axios.post('http://localhost:29182/hotel/order/creategoods', this.ruleForm)
            .then((response)=>{
              let jsonResult = response.data;
              if (jsonResult.state == 20000 ){
                  confirm("添加订单成功");
                this.gotoWare();

              }else {
                confirm("添加失败")
              }
            })/*response => {
              this.dialogVisible = false; // 隐藏对话框
              // 处理你的响应数据
            })*/
           /* .catch(error => {
              // 处理错误
            });*/
      },


    },
  mounted() {
      this.fetchData();
  }
}
</script>

<style scoped>

</style>